package tests;

import static org.junit.Assert.*;

import java.awt.Color;

import org.junit.*;

import MULE.Model.*;
import MULE.Model.Panel.NotEnoughMoneyException;

/**
 * This class tests a Store buy method
 * 
 * 
 * @ author Anastasiya Cotton @ version 1.0 11.11.2013
 */

public class StoreTests {
	private Player p;

	@Before
	public void setUp() {
		p = new Player(1, "Test", Race.HUMAN, Color.RED);
		p.getInventory().add(Resource.MONEY, 200);

	}

	// testing the adding of proper amount of resource to player inventory
	@Test
	public void testBuy() throws NotEnoughMoneyException {
		try {
			Store.buy(p, Resource.FOOD, 1);
			assertEquals(1, p.getInventory().getAmount(Resource.FOOD));
		} catch (NotEnoughMoneyException e) {
			assertTrue(false);
		}
	}

	// testing the proper removal of money from player
	@Test
	public void testBuy2() throws NotEnoughMoneyException {
		try {
			Store.buy(p, Resource.FOOD, 1);
			assertEquals(170, p.getInventory().getAmount(Resource.MONEY));
		} catch (NotEnoughMoneyException e) {
			assertTrue(false);
		}
	}

	// test to not enough money exception to buy resource
	@Test
	public void testBuy3() throws NotEnoughMoneyException {
		try {
			Store.buy(p, Resource.FOOD, 9);
			assertFalse("Not enough Money", true);
		} catch (NotEnoughMoneyException e) {
			assertTrue(true);
		}

	}

	// test to not enough money exception to buy resource
	@Test
	public void testBuy4() throws NotEnoughMoneyException {
		try {
			Store.buy(p, Resource.FOOD, 11);
			assertFalse("Not enough Money", true);
		} catch (NotEnoughMoneyException e) {
			assertTrue(true);
		}
	}

	// test to buy mule and add it to player's inventory
	@Test
	public void testBuy5() throws NotEnoughMoneyException {
		try {
			Store.buy(p, Resource.MULE, 1);
			assertEquals(1, p.getInventory().getAmount(Resource.MULE));
		} catch (NotEnoughMoneyException e) {
			assertTrue(false);
		}
	}
}